Ext.ns('Wlanauth.role');

Wlanauth.role.ManagerPanel = Ext.extend(Ext.Panel,{
	title:'角色管理',
	iconCls:'class',
	constructor:function(config){
		Ext.apply(this,config);
		
		var formpanel = new Wlanauth.role.FormPanel({
			border:false,
			autoScroll:true,
			autoHeight:true,
			title:'角色资料',
			buttons:[{
	        	text:'保存',
	        	iconCls:'edit',
	        	handler:function(){
	        		formpanel.doSubmit();
	        	}
	        },{
	        	text:'取消',
	        	iconCls:'cancel',
	        	handler:function(){
	        		ZZExt.ApplicationContext.removeTabCmp(this);
	        	},
	        	scope:this
	        }],
			setMode:function(mode){
				this.editMode= mode;
				if(mode=='create'){
					this.setTitle('角色资料>><font color="blue">新增</font>');
					
				} else {
					this.setTitle('角色资料>><font color="blue">修改</font>');
					
				}
			}
		});
		var grid = new Wlanauth.role.GridPanel({
			border:false,
			editObject:function(){
				var r = this.getSelectionModel().getSelected();
				if(!r){Ext.Msg.alert('提示','请选择一项');return;}
				formpanel.setMode('update');
				if(!r.get('editable')){
					formpanel.setTitle('角色资料>><font color="red">查看(不可编辑)</font>');
				}
				
				formpanel.loadDataById(r.get('id'));
				
			},
			addObject:function(){
				formpanel.setMode('create');
				formpanel.getForm().reset();
			}
			
		});
		formpanel.on('actionSuccess',function(form,action){
	 		
			var msg = '操作成功,数据已保存!';
			if(formpanel.editMode!='update'){
				msg +=' 切换至修改状态';
			} else {
				msg +=' 可继续修改';
			}
	 		formpanel.editMode='update';
	 		formpanel.setTitle('角色资料>><font color="blue">修改</font>');
	 		form.findField('entity.id').setValue(action.result.data);
	 		Ext.Msg.alert('提示',msg,function(){
	 			//刷新grid
		 		grid.getStore().reload();
	 		});
	 		
		});
		
		Wlanauth.role.ManagerPanel.superclass.constructor.call(this,{
			layout:'border',
			frame:false,
			items:[{
				region:'west',
				width:300,
				margins : '2',
				layout:'fit',
				items:grid,
			},{
				region:'center',
				margins : '2 2 2 1',
				autoScroll:true,
				items:formpanel
			}]
		});
		formpanel.setMode('create');
		grid.fireEvent('autoload');
	}
});

Ext.reg('wlanauth.role.managerpanel',Wlanauth.role.ManagerPanel);